* REPLICATION SYNTAX
* Askim, Gendźwiłł, Klausen (2025) Problem Indicators and Territorial Restructuring: Do Institutional Decision Rules Matter?

* load dataset / enter valid path
use "...\jpp_dataset.dta", clear

* Scheme Tufte used for graphs
ssc install scheme_tufte

**# CODEBOOK

* WB_code - 3-digit World Bank country code
* country - country name (string)
* cntry - country name (factor/numeric variable)
* ISO_code - 2-digit ISO country code
* IAD_nat - rules for territorial change: 1 - centralized, 0 - dispersed (based on Swianiewicz et al. 2022)
* year - year
* reform3 - ATS change (3% threshold)
* reform4 - ATS change (4% threshold)
* reform5 - ATS change (5% threshold), baseline dependent variable
* reform6 - ATS change (6% threshold)
* reform7 - ATS change (7% threshold)
* gdp_g_lag1 - GDP growth rate in year t-1 (World Bank)
* gdp_g_lag2 - GDP growth rate in year t-2 (World Bank)
* gdp_g_lag3 - GDP growth rate in year t-3 (World Bank)
* recession2Yr - recession occurred in the previous 2 years (at least in t-1 or t-2)
* recession3Yr - recession occurred in the previous 3 years (at least in t-1, t-2, or t-3)
* PS_lag1 - Policy Scope index in year t-1 (Local Autonomy Index database, Ladner et al. 2022)
* PS_lag2 - Policy Scope index in year t-2 (Local Autonomy Index database, Ladner et al. 2022)
* PS_lag3 - Policy Scope index in year t-2 (Local Autonomy Index database, Ladner et al. 2022)
* PS_change2Y_01 - increase of Policy Scope occurred in the previous 2 years (at least in t-1 or t-2)
* PS_change3Y_01 - increase of Policy Scope occurred in the previous 3 years (at least in t-1, t-2, or t-3)
* urbanpop_lag1 - % of urban population in year t-1 (World Bank)
* urbanpop_lag2 - % of urban population in year t-2 (World Bank)
* urbanpop_lag3 - % of urban population in year t-3 (World Bank)
* urbanpop_change2Y - positive change in the proportion of urban population between t−1 and t−2 (pct points)
* urbanpop_change3Y - positive change in the proportion of urban population between t−1 and t−3 (pct points)
* election - national parliamentary election (IDEA International election database)
* n_municip - number of municipalities (LAI database, Ladner et al. 2022, verified, year t)
* population - population (World Bank, year t)
* avg_size_lag1 - average municipality size (year t-1)
* log_avg_size_lag1 - log average municipality size (year t-1)


**# DESRIPTIVE ANALYSES

* graphs (Figure 1)

* graph - incremental reforms in Iceland
twoway (line n_municip year) if country=="Iceland", ytitle(Number of municipalities) xtitle(Year) xline(1991 1995 1998 1999 2002 2003 2005 2006 2007 2012 2020, lpattern(dash)) scheme(tufte) xsize(4) ysize(4)

* graph - one-off reform in Denmark
twoway (line n_municip year) if country=="Denmark", ytitle(Number of municipalities) xtitle(Year) xline(2007, lpattern(dash)) scheme(tufte) xsize(4) ysize(4)


**# MAIN MODELS (Table 2)

* MODEL 1: RE logit, no controls, no interactions
xtlogit reform5 i.recession2Yr c.urbanpop_change2Y i.PS_change2Y_01, re vce (cl cntry)
eststo m1
* export to table
outreg2 using terref_v3, excel replace ctitle(no controls, no interactions)

* MODEL 2: RE logit, + controls, no interactions
xtlogit reform5 i.recession2Yr c.urbanpop_change2Y i.PS_change2Y_01 c.log_avg_size_lag1 i.election, re vce (cl cntry)
eststo m2
* export to table
outreg2 using terref_v3, excel append ctitle(controls, no interactions)
* export margins from m2 (all countries)
xtlogit reform5 i.recession2Yr c.urbanpop_change2Y i.PS_change2Y_01 c.log_avg_size_lag1 i.election, re vce (cl cntry)
margins, dydx (i.recession2Yr c.urbanpop_change2Y i.PS_change2Y_01) level(95) saving("C:\data\margins3.dta", replace)

* MODEL 3: RE logit, no controls, with interactions 
xtlogit reform5 i.recession2Yr##i.IAD_nat c.urbanpop_change2Y##i.IAD_nat i.PS_change2Y_01##i.IAD_nat, re vce (cl cntry)
eststo m3
* export to table
outreg2 using terref_v3, excel append ctitle(no controls, interactions)

* MODEL 4: RE logit, + controls + interactions (baseline model)
xtlogit reform5 i.recession2Yr##i.IAD_nat c.urbanpop_change2Y##i.IAD_nat i.PS_change2Y_01##i.IAD_nat c.log_avg_size_lag1##i.IAD_nat i.election##i.IAD_nat, re vce (cl cntry)
eststo m4
* export to table
outreg2 using terref_v3, excel append ctitle(no controls, interactions)
* margins, export conditional margins from m4 (dispersed vs centralized countries)
margins, dydx (i.recession2Yr c.urbanpop_change2Y i.PS_change2Y_01) at(IAD_nat=(0(1)1)) level(95) saving("C:\data\margins1.dta", replace)


**# MAIN GRAPH (Figure 2)
* Comparison of Centralized, Dispersed, and All countries 

frame create margins
frame change margins
clear
use "C:\data\margins1.dta"
append using "C:\data\margins3.dta"

generate iv = 1 in 1 
replace iv = 1 in 2
replace iv = 1 in 7
replace iv = 2 in 3
replace iv = 2 in 4
replace iv = 2 in 8
replace iv = 3 in 5
replace iv = 3 in 6
replace iv = 3 in 9

gen posx = iv - 0.2 if _at == .
replace posx = iv if _at == 1
replace posx = iv + 0.2 if _at == 2

twoway (rspike _ci_lb _ci_ub posx, lc(gray)) (scatter _margin posx if _at==., msymbol(D)) (scatter _margin posx if _at==1, msymbol(T)) (scatter _margin posx if _at==2, msymbol(S)), xtitle("") xlabel(1 "Recession" 2 "Urbanization" 3 `" "Increased" "Policy Scope" "') ytitle("Effect on the probability of the change (AME)" ) yline(0, lpattern(dash)) scheme(tufte) legend(order(2 "All countries" 3 "Dispersed" 4 "Centralized")) text(0.15 1.1 "(ns)" 0.15 2.1 "***" 0.15 3.1 "***") saving(basic, replace)

